import matplotlib.pyplot as plt
import numpy as np


# Plotting
fig, ax = plt.subplots(figsize=(8, 6))

plt.tick_params(labelsize=25)
font1 = {'weight' : 'bold','size' : 30,}
X_name = "Time"
plt.xlabel(X_name, fontdict=font1)
Y_name = "Bandwidth"
plt.ylabel(Y_name, fontdict=font1)

ax.set_xlim(-5.06, 5.5)
ax.set_ylim(0, 21)

ax.grid(True, axis='y', linestyle='--', linewidth=0.7)  # Gridlines for the y-axis with dashed lines


spacing = 0.0
bars1 = ax.bar(0, 20, 10, label='F1', color='white', edgecolor='#4169e1', hatch='//', linewidth=3)
bars2 = ax.bar(-0.333333, 15, 1.333, label='F2', color='white', edgecolor='#4169e1', hatch='\\', linewidth=3)


# Legend
plt.legend(loc='best', ncol=1, prop={'size': 24})
plt.xticks([])  # 隐藏x轴刻度标签
plt.yticks([])  # 隐藏y轴刻度标签

ax.spines['left'].set_linewidth(3)   # y轴线条加粗
ax.spines['bottom'].set_linewidth(3) # x轴线条加粗
# 隐藏上方和右侧的边框
ax.spines['top'].set_visible(False)    # 隐藏上方边框
ax.spines['right'].set_visible(False)  # 隐藏右侧边框

# 添加 x 轴正方向箭头
ax.annotate('', xy=(5.5, 0), xytext=(5.7, 0), 
            arrowprops=dict(facecolor='black', arrowstyle='<-, head_width=0.6, head_length=1.2', lw=3, ))

# 添加 y 轴正方向箭头
ax.annotate('', xy=(-5.06, 21), xytext=(-5.06, 21.5), 
            arrowprops=dict(facecolor='black', arrowstyle='<-, head_width=0.6, head_length=1.2', lw=3, ))

# plt.axhline(y=5, color='k', linestyle='-.', linewidth=3, alpha=0.7)
plt.axhline(y=10, color='k', linestyle='-.', linewidth=3, alpha=0.7)
# plt.axhline(y=15, color='k', linestyle='-.', linewidth=3, alpha=0.7)
#ax.text(x=-0.7, y=16, s="F2 FCT=0.67*t2", fontsize=30, color='black', ha='center', va='center', weight='bold')
#ax.text(x=0, y=21, s="F1 FCT=t1", fontsize=30, color='black', ha='center', va='center', weight='bold')

plt.legend(loc='upper left', bbox_to_anchor=(0,0.95), ncol=1, prop={'size': 30, 'weight': 'normal'})

# Show the plot
plt.tight_layout()
png_filename = 'img/slowdown-2.pdf'
plt.savefig(png_filename, format='pdf', dpi=300, bbox_inches='tight')
png_filename = 'img/slowdown-2.png'
plt.savefig(png_filename, format='png', dpi=300, bbox_inches='tight')